import signFun from './sign.js';
const baseUrlObj = {
  //'develop': 'https://sit-canteen-h5.yto56test.com/merchant-api', //开发版接口地址
  'develop': 'https://vue.facest.cn/merchant-api', //开发版接口地址
  'release': 'https://canteen-merchant-h5.hzhjxg.cn/gateway'
}
const accountInfo = my.getAccountInfoSync();
const envVersion = accountInfo.miniProgram.envVersion;
const baseUrl = baseUrlObj[envVersion];

function request(option) {
  my.showLoading();
  let token = my.getStorageSync({ key: 'token' });
  return my.request({
    url: `${baseUrl}${option.url}`,
    method: option.method,
    data: signFun(option.data),
    dataType: 'json',
    headers: {
      'content-type': 'application/x-www-form-urlencoded', //默认值
      'Authorization': token.data ? `bearer ${token.data}` : ''
    },
    complete: function () {
      my.hideLoading();
    },
  }).then(res => {
    return Promise.resolve(res.data);
  }).catch(err => {
    return Promise.resolve(err.data);
  });
}
export default request;